<template>
  <button class="h-btn" :class="[typeClass, sizeClass]" @click="clickHandler">
    <slot></slot>
  </button>
</template>

<script>
export default {
  data() {
    return {};
  },
  props: {
    /* 
根据不同的type值 给button 绑定不同的类名
"default" ->h-btn-type-default
"primary" ->h-btn-type-primary
"danger" ->h-btn-type-danger
通用计算公式：x-> h-btn-type-{x} 
*/

    //颜色类型type
    type: {
      type: String,
      default: "default",
      validator: (value) => {
        // value表示传过来的值  console.log(value); default这些
        const typeList = ["default", "primary", "danger"];
        return typeList.includes(value);
      },
    },
    // 大小类型size（尺寸）
    size: {
      type: String,
      default: "default", //props的默认配置，如果不传则以默认为主
      validator: (value) => {
        // 对传入的参数值做校验，如果满足条件就返回true，不满足就返回false
        const sizeList = ["default", "large", "small"];
        return sizeList.includes(value);
      },
    },
  },
  computed: {
    typeClass() {
      return `h-btn-type-${this.type}`;
    },
    sizeClass() {
      return `h-btn-size-${this.size}`;
    },
  },
  methods: {
    clickHandler(e) {
      this.$emit("click", e);
    },
  },
};
</script>
<style scoped lang="less" >
// 默认背景色 默认大小
.h-btn {
  line-height: 1.499;
  position: relative;
  display: inline-block;
  font-weight: 400;
  white-space: nowrap;
  text-align: center;
  background-image: none;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.015);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.645, 0.045, 0.355, 1);
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  touch-action: manipulation;
  padding: 5px 10px;
  font-size: 14px;
  border-radius: 4px;
  color: rgba(0, 0, 0, 0.65);
  background-color: #fff;
  border: 1px solid #d9d9d9;
}
.h-btn:focus {
  outline: 0;
}
// primary类
.h-btn-type-primary {
  color: #fff;
  background-color: #1890ff;
  border-color: #1890ff;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
}
// danger类
.h-btn-type-danger {
  color: #fff;
  background-color: #ff4d4f;
  border-color: #ff4d4f;
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.12);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.045);
}

// size:small
.h-btn-size-small {
  padding: 4px 8px;
  font-size: 12px;
}
// size:large
.h-btn-size-large {
  padding: 6px 12px;
  font-size: 30px;
}
</style>